<template>
  <div class="right-menu">
    <div class="right-menu-item shift-icon">
      <div v-show="isDayShift">
        <svg-icon icon-class="sun" /> 白班
      </div>
      <div v-show="!isDayShift">
        <svg-icon icon-class="moon" /> 夜班
      </div>
    </div>
    <div class="right-menu-item currentTime">{{ nowTime }}</div>
    <div class="right-menu-item user-name">{{ nickName }} </div>
    <div class="right-menu-item logout" @click="logout">退出</div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { parseTime } from '@/utils'

export default {
  name: 'RightMenu',
  data() {
    return {
      isDayShift: true,
      nowTime: ''
    }
  },
  computed: {
    ...mapGetters([
      'nickName'
    ])
  },
  mounted() {
    this.nowTimes()
  },
  methods: {
    shiftChange() {
      const hour = new Date().getHours() //  0 ~ 23
      this.isDayShift = hour >= 8 && hour <= 20
    },
    nowTimes() {
      this.nowTime = parseTime(new Date(), '{y}-{m}-{d} {h}:{i}:{s}')
      setInterval(this.nowTimes, 1000)
      this.shiftChange()
      this.clear()
    },
    clear() {
      clearInterval(this.nowTimes)
      this.nowTimes = null
    },
    async logout() {
      // console.log('logout')
      await this.$store.dispatch('user/logout')
      this.$router.push('/login')
    }
  }
}
</script>

<style lang="scss" scoped>
@import "~@/styles/variables.scss";

.title-box{
    width: 100%;
    height: 50px;
    position: absolute;
    top: $navBarHeight;
    img{
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
    }
    p{
        display: inline-block;
        margin: 0;
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        span {
        line-height: 50px;
        font-size: 30px;
        font-weight: bold;
        letter-spacing: 2px;
        text-shadow: 1px 1px 0px rgb(0 149 140), 1px 2px 0px rgb(0 149 160), 1px 3px 0px rgb(0 149 180), 1px 4px 0px rgb(0 149 200), 1px 5px 0px rgb(0 149 227);
    }
    }
}
</style>
